package com.example.myapplication.login;


import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.mvp.mvp.view.BaseFragment;
import com.example.myapplication.R;
import com.example.myapplication.a_mvp.contract.MyContract;
import com.example.myapplication.a_mvp.presenter.MyPresenter;
import com.example.myapplication.a_utils.Dag_Mod;
import com.example.myapplication.a_utils.DaggerDag_Com;
import com.example.myapplication.b_entity.Login_Entity;
import com.example.myapplication.b_entity.Daxia;
import com.example.myapplication.b_entity.Reg_Entity;

import java.util.List;
import java.util.Timer;
import java.util.TimerTask;

/**
 * A simple {@link Fragment} subclass.
 */
public  class Reg_Fragment extends BaseFragment<MyPresenter> implements MyContract.MyView {

    private ImageView reg_img;
    private TextView main_text;
    private EditText main_edi;
    private Button main_butt;
    private TextView main_text2;




    @Override
    public int findlayout() {
        return R.layout.fragment_reg_;
    }
    //接口回调数据
    interface GetType{
        void Type(int  i);
    }
    private Login_Fragment.GetType getType;
    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getType = (Login_Fragment.GetType) getActivity();
    }

    public void initView() {
        reg_img = (ImageView) myview.findViewById(R.id.reg_img);
        main_text = (TextView) myview.findViewById(R.id.main_text);
        main_edi = (EditText) myview.findViewById(R.id.main_edi);
        main_butt = (Button) myview.findViewById(R.id.main_butt);
        main_text2 = (TextView) myview.findViewById(R.id.main_gologin);

        final Timer timer = new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                String trim = main_edi.getText().toString().trim();
                if (trim.equals("")){
                    getActivity().runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            main_butt.setBackground(getResources().getDrawable(R.drawable.mybutton));
                            main_butt.setEnabled(false);
                        }
                    });

                }else{
                    getActivity().runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            main_butt.setBackground(getResources().getDrawable(R.drawable.mybutton));
                            main_butt.setEnabled(true);

                        }
                    });
                }
            }
        },0,20);
        DaggerDag_Com.builder().dag_Mod(new Dag_Mod(this)).build().reg(this);
        main_butt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mypre.reg("a","a");

            }
        });
        main_text2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getType.Type(2);
            }
        });
    }

    @Override
    public void initData() {


    }

    @Override
    public void show_reg(Reg_Entity reg_entity) {
        if (reg_entity.getCode().equals("200")){
            getType.Type(2);
        }
    }

    @Override
    public void show_login(Login_Entity login_entity) {


    }

    @Override
    public void show_daxia(List<Daxia.DataBean> list) {

    }




}
